package android.system;

import android.app.Application;
import android.content.ContentResolver;
import android.content.Context;
import android.system.utils.Database;
import android.system.utils.LogUtils;
import android.system.utils.NetWorkManager;
import android.telephony.TelephonyManager;

public class SysAplication extends Application{
	public static final boolean LOG_ON_OFF = true;//log开关
	public static final boolean isToast = true;//显示测试 提示框
	public static final int MAX_COUNT = 20;
	//private TelephonyManager mTelephonyManager;
	private static  SysAplication me = null;
	private NetWorkManager mNetWorkManager=null;
	private Database mDatabase = null;
	private ContentResolver mContentResolver = null;
	private String SubscriberId=null;
	public SysAplication(){
		me = this;
	}
	public static SysAplication getMe(){
		return me;
	}
	@Override
	public void onCreate() { 
		// TODO Auto-generated method stub
		super.onCreate();
		log("onCreate");
		init();
		//mTelephonyManager=(TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
		mContentResolver = this.getContentResolver();
		mDatabase = new Database(this);
		mDatabase.open();
		mNetWorkManager = new NetWorkManager(this);;
		
	}
	void init(){
		TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
	//	SubscriberId = tm.getDeviceId();
		SubscriberId = tm.getSubscriberId(); 
	}
	@Override
	public void onTerminate() {
		// TODO Auto-generated method stub
		super.onTerminate();
	}
	public long getCurrenTime(){
		return System.currentTimeMillis();
	}
	public Database getDB(){
		return mDatabase;
	}
	public NetWorkManager getNetWorkManager(){
		return mNetWorkManager;
	}
	//获取 IMSI
	public String getPhoneNumber(){
		//log("PhoneNumber="+mTelephonyManager.getLine1Number());
		
//		TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
//		String IMEI = tm.getDeviceId();
//		String IMSI = tm.getSubscriberId(); 
		//if(mTelephonyManager==null)return "-1";
		//String number = mTelephonyManager.getSubscriberId();
		log("number="+SubscriberId);
		if(SubscriberId==null||SubscriberId.trim().equals("")){
			SubscriberId="-1";
		}
		return SubscriberId;
	}
	public static boolean isAirplaneModeOn(Context context) {
		return false;
//          return Settings.System.getInt(context.getContentResolver(),
//                    Settings.System.AIRPLANE_MODE_ON, 0) != 0;
     }

	private void log(String msg){
		LogUtils.logD("SysAplication", msg);
	}
	
	private void logE(String msg){
		LogUtils.logD("SysAplication", msg);
	}

}
